package com.example.havi.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.havi.R;
import com.example.havi.bean.EmojiBean;
import com.example.havi.bean.MoreMenuBean;

import java.util.List;

public class MoreMenusAdapter extends RecyclerView.Adapter {

    private final Context context;
    List<MoreMenuBean> emojis;

    public MoreMenusAdapter(Context context, List<MoreMenuBean> emojis) {
        this.emojis = emojis;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_more_menu,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, final int position) {
        final ViewHolder holder1 = (ViewHolder) holder;
        final MoreMenuBean bean = emojis.get(position);
        holder1.menu_pic_iv.setImageResource(bean.getDrawableId());
        holder1.menu_name_tv.setText(bean.getMenuName());
        holder1.rootView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null)
                    listener.onItemClick(holder1.rootView,position,bean);
            }
        });
    }


    @Override
    public int getItemCount() {
        return emojis.size();
    }


    class ViewHolder extends RecyclerView.ViewHolder {
        ImageView menu_pic_iv;
        TextView menu_name_tv;
        View rootView;
        public ViewHolder(View itemView) {
            super(itemView);
            menu_pic_iv = itemView.findViewById(R.id.menu_pic_iv);
            menu_name_tv = itemView.findViewById(R.id.menu_name_tv);
            rootView = itemView;
        }
    }

    private OnItemClickListener listener;

    public void setOnItemClickListener(OnItemClickListener l){
        listener = l;
    }

    public interface OnItemClickListener{
        void onItemClick(View view, int position, MoreMenuBean bean);
    }
}
